<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>{$lang.cp_home}{if $ur_here} - {$ur_here} {/if}</title>
<meta name="robots" content="noindex, nofollow">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="styles/general.css" rel="stylesheet" type="text/css" />
<link href="styles/main.css" rel="stylesheet" type="text/css" />
{insert_scripts files="common.js"}
<script language="JavaScript">
<!--
// 这里把JS用到的所有语言都赋值到这里
{foreach from=$lang.js_languages key=key item=item}
var {$key} = "{$item}";
{/foreach}
//-->
</script>
</head>
<body>
<div id="ajaxload" style="position:absolute;z-index: 100 ;width:100%;height:1000px;background-color: #000;opacity: 0.5;display: none;">
  <img src="./images/ajax-loader2.gif"  style=" position: fixed;top: 50%;left:50%;z-index:101; opacity: 1;"/>
</div>
<h1>
{if $action_link}
<span class="action-span"><a href="{$action_link.href}">{$action_link.text}</a></span>
{/if}
{if $action_link2}
<span class="action-span"><a href="{$action_link2.href}">{$action_link2.text}</a>&nbsp;&nbsp;</span>
{/if}
<span class="action-span1"><a href="index.php?act=main">{$lang.cp_home}</a> </span><span id="search_id" class="action-span1">{if $ur_here} - {$ur_here} {/if}</span>
<div style="clear:both"></div>
</h1>

<script src="../js/jquery-1.9.1.min.js" type="text/javascript"></script>
<!-- start goods form -->
<div class="tab-div">
  <div id="tabbar-div" style="display: none;">
    <p>
      <span class="tab-front" id="general-tab">{$lang.tab_general}</span><span
      class="tab-back" id="detail-tab">{$lang.tab_content}</span><span
      class="tab-back" id="goods-tab">{$lang.tab_goods}</span>
    </p>
  </div>

  <div id="tabbody-div">

    <form action="course_vedio.php" method="post" enctype="multipart/form-data" id="img_form">
      
      
      <table width="90%" id="general-table">
      <tr>
        <td class="narrow-label"> 视频封面</td>
        <td> <input type="file" name="thumb_img" /></td>
        </tr>
      </table>
       <input type="hidden" name="vedio_id" id="vedio_id"  value="{$vedio.vedio_id}"/>
        <input type="hidden" name="act"   value="{$img_form_action}"/>
    </form>


    <form  id="uploadForm" action="" method="post" enctype="multipart/form-data" name="theForm" onsubmit="" id="" >
    <table width="90%" id="general-table">
      <tr>
        <td class="narrow-label">{$lang.title}</td>
        <td>
        <input type="text" name="key" id="key"　size ="40" maxlength="60" value="{$vedio.title|escape}" />
        {$lang.require_field}
        </td>
      </tr>          
     
      <tr>
        <td class="narrow-label">{$lang.cat} </td>
        <td>
          <select name="x:course_id" id="course_id"　onchange="">
            <option value="0">{$lang.select_plz}</option>
           {foreach from=$course_list item=c}
              <option value="{$c.course_id}" {if $c.course_id eq $vedio.course_id} selected="selected" {/if}>{$c.title}</option>
           {/foreach}
          </select>
         {$lang.require_field}

         </td>
      </tr>
     
    
      <tr>
        <td class="narrow-label">{$lang.is_open}</td>
        <td>
        <input type="radio" name="x:is_show" value="1"  {if $vedio.is_show ==1 || $form_action =='insert'}checked{/if}> {$lang.isopen}
       <input type="radio" name="x:is_show" value="0" {if $vedio.is_show == 0 && $form_action != 'insert'}checked{/if}> {$lang.isclose}{$lang.require_field} </td>
      </tr>
     
     

      <tr>
        <td class="narrow-label">{$lang.lable_description}</td>
        <td><textarea name="x:description" id="description" cols="40" rows="5">{$vedio.description|escape}</textarea></td>
      </tr>
      <tr style="display:none;">
        <td class="narrow-label">{$lang.external_links}</td>
        <td><input name="link_url" type="text" id="link_url" value="{if $article.link neq ''}{$article.link|escape}{else}http://{/if}" maxlength="60" /></td>
      </tr>
      <tr >
        <td class="narrow-label">{$lang.upload_file}</td>
        <td><input type="file" name="file">

          <span class="narrow-label" style="display: none;">{$lang.file_url}
          <input name="file_url" type="text" value="{$article.file_url|escape}" size="30" maxlength="255" />
          </span>

          </td>
      </tr>
    </table>

    <table width="90%" id="detail-table" style="display:none">
     <tr><td>{$FCKeditor}</td></tr>
    </table>

    <table width="90%" id="goods-table" style="display:none">
      <!-- 商品搜索 -->
      <tr>
      <td colspan="5">
        <img src="images/icon_search.gif" width="26" height="22" border="0" alt="SEARCH" />
       
        <input type="button" value="{$lang.button_search}" onclick="searchGoods()" class="button" />
      <td>
      </tr>
      <!-- 商品列表 -->
      <tr>
        <th>{$lang.all_goods}</th>
        <th>{$lang.handler}</th>
        <th>{$lang.send_bouns_goods}</th>
      </tr>
      <tr>
        <td width="45%" align="center">
          <select name="source_select" size="20" style="width:90%" ondblclick="sz.addItem(false, 'add_link_goods', articleId)" multiple="true">
          </select>
        </td>
        <td align="center">
          <p><input type="button" value="&gt;&gt;" onclick="sz.addItem(true, 'add_link_goods', articleId)" class="button" /></p>
          <p><input type="button" value="&gt;" onclick="sz.addItem(false, 'add_link_goods', articleId)" class="button" /></p>
          <p><input type="button" value="&lt;" onclick="sz.dropItem(false, 'drop_link_goods', articleId)" class="button" /></p>
          <p><input type="button" value="&lt;&lt;" onclick="sz.dropItem(true, 'drop_link_goods', articleId)" class="button" /></p>
        </td>
        <td width="45%" align="center">
          <select name="target_select" multiple="true" size="20" style="width:90%" ondblclick="sz.dropItem(false, 'drop_link_goods', articleId)">
            {foreach from=$goods_list item=goods}
            <option value="{$goods.goods_id}">{$goods.goods_name}</option>
            {/foreach}
          </select>
        </td>
      </tr>
    </table>
    <div class="button-div">
      <input name="token" type="hidden" value="{$uptoken}">
      <input type="hidden" name="act" value="{$form_action}" />
      <input type="hidden" name="old_title" value="{$vedio.title}"/>
      <input type="hidden" name="x:id"　id="vedio_id"　value="{$vedio.vedio_id}" />
      <input type="button" value="{$lang.button_submit}" class="button"
      onclick="doUpload();"  />
      <input type="reset" value="{$lang.button_reset}" class="button" />
    </div>

    </form>
   <hr/>
    <p style="margin-left:200px; color:#C43926">提示：请在上面的完整视频上传好之后，在上传剪辑视频</p>
    <form action="" method="post" enctype="multipart/form-data" id="clips_form" style="margin-left:200px; ">
      <p><input type="file" name="file"/></p>
      <p><input type="button" value="上传剪辑" onclick="uploadClick(this);" /></p>
      <input type="hidden" name="vedio_id" id="vedio_id"  value="{$vedio.vedio_id}"/>
      <input type="hidden" name="clips_act" id="clips_act"  value="{$clips_form_action}"/>

    </form>


    
  </div>

</div>

<script>
   /* 上传视频剪辑 */
   function uploadClick(obj){
    var form_obj = $(obj).parents('form');
    var vedio_id=form_obj.find('#vedio_id').val();
    var act= form_obj.find('#clips_act').val();
    
   }

</script>




<!-- end goods form -->
<script type="text/javascript">

 function doUpload() {
   var id =$('#vedio_id').val();
   var file=$("#uploadForm input[type='file']").val();
   
  if(id>0 && file){
       //上传到七牛-编辑
       
        $('#ajaxload').show();
      setTimeout('doUpload2()',1000);
  }else if(file){
      //上传到七牛-添加
       $('#ajaxload').show();
      setTimeout('doUpload1()',1000);
  }else{
    // 修改本地字段

    doUpload3();
  }
     
       //doUpload1();  
  }

/* 七牛 ajax提交表单-添加视频 */
  function doUpload1() {  
    
     var formData = new FormData($( "#uploadForm" )[0]);  
     $.ajax({  
          url: 'http://upload.qiniu.com/' ,  
          type: 'POST',  
          data: formData,  
          async: false,  
          cache: false,  
          contentType: false,  
          processData: false, 
          success: function (data) { 
            console.log(data);
             var title=data.key;
             var course_id=data.course_id;
             var is_show = data.is_show;
             var description = data.description;
             var vedio_url='http://oq4vbry69.bkt.clouddn.com/'+data.key;
              
               $.ajax({
                    url: 'course_vedio.php?act=insert_vedio' ,  
                    type: 'POST',
                    dataType: "json",  
                    data:{"title":title,"course_id":course_id,"is_show":is_show,"description":description,"vedio_url":vedio_url}, 
                     success: function (data) { 

                         if(parseInt(data.status)==1){
                             //提交封面表单
                             $('#vedio_id').val(data.insert_id);
                             $('#img_form').submit();
                              
                         }
                     },
                    error: function (data) {  
                     alert('插入数据库失败！'); 
                     //location.reload();
                    }   
                                     
                  
               });
            
          },  
          error: function (data) {  
              alert('上传出错，请修改文件名称，重新上传'); 
               //location.reload(); 
          }  
     });  
}  
/* 七牛 ajax提交表单-编辑视频 */
  function doUpload2() {  
    
     var formData = new FormData($( "#uploadForm" )[0]); 
     //console.log(formData);
     $.ajax({  
          url: 'http://upload.qiniu.com/',  
          type: 'POST',  
          data: formData,  
          async: false,  
          cache: false,  
          contentType: false,  
          processData: false, 
          success: function (data) { 
             
             var title=data.key;
             var course_id=data.course_id;
             var is_show = data.is_show;
             var description = data.description;
             var vedio_url='http://oq4vbry69.bkt.clouddn.com/'+data.key;

             var vedio_id = $('#vedio_id').val();
            
               $.ajax({
                    url: 'course_vedio.php?act=update_vedio' ,  
                    type: 'POST',
                    dataType: "json",  
                    data:{"title":title,"course_id":course_id,"is_show":is_show,"description":description,"vedio_url":vedio_url,"vedio_id":$('#vedio_id').val()}, 
                     success: function (data) { 
                         if(parseInt(data.status)==1){
                             //提交封面表单
                             //$('#vedio_id').val(data.vedio_id);
                             $('#img_form').submit();
                              
                         }
                     },
                    error: function (data) {  
                     alert('插入数据库失败！'); 
                     //location.reload();
                    }   
                                     
                  
               });
            
          },  
          error: function (data) {  
              alert('上传出错，请修改文件名称，重新上传'); 
               //location.reload(); 
          }  
     });  
} 

/* 不上传,只修改本地字段 */
  function doUpload3() {  
     var title = $('#key').val(); 
     var course_id = $('#course_id').val();
     var is_show = $("input[name='x:is_show']:checked").val();
     var description = $('#description').val();
     var id = $('#vedio_id').val();
   $.ajax({  
    url: 'course_vedio.php?act=update' ,  
    type: 'POST',
    dataType:"json",  
    data: {"title":title,"course_id":course_id,"is_show":is_show,"description":description,"id":id},          
    success: function (data) { 
      
        if(parseInt(data.status)==1){

           //提交封面表单
          
           $('#img_form').submit();

         }

       },  
       error: function (data) {  
        alert('修改出现问题！'); 
        location.reload(); 
      }  

    });  
 } 

</script>





<script language="JavaScript">

var articleId = {$article.article_id|default:0};
var elements  = document.forms['theForm'].elements;
var sz        = new SelectZone(1, elements['source_select'], elements['target_select'], '');

{literal}
onload = function()
{
  // 开始检查订单
  startCheckOrder();
}

function validate()
{
  var validator = new Validator('theForm');
  validator.required('title', no_title);
{/literal}
{if $article.cat_id >= 0}
  validator.isNullOption('article_cat',no_cat);
{/if}
{literal}

  return validator.passed();
}

document.getElementById("tabbar-div").onmouseover = function(e)
{
    var obj = Utils.srcElement(e);

    if (obj.className == "tab-back")
    {
        obj.className = "tab-hover";
    }
}

document.getElementById("tabbar-div").onmouseout = function(e)
{
    var obj = Utils.srcElement(e);

    if (obj.className == "tab-hover")
    {
        obj.className = "tab-back";
    }
}

document.getElementById("tabbar-div").onclick = function(e)
{
    var obj = Utils.srcElement(e);

    if (obj.className == "tab-front")
    {
        return;
    }
    else
    {
        objTable = obj.id.substring(0, obj.id.lastIndexOf("-")) + "-table";

        var tables = document.getElementsByTagName("table");
        var spans  = document.getElementsByTagName("span");

        for (i = 0; i < tables.length; i++)
        {
            if (tables[i].id == objTable)
            {
                tables[i].style.display = (Browser.isIE) ? "block" : "table";
            }
            else
            {
                tables[i].style.display = "none";
            }
        }
        for (i = 0; spans.length; i++)
        {
            if (spans[i].className == "tab-front")
            {
                spans[i].className = "tab-back";
                obj.className = "tab-front";
                break;
            }
        }
    }
}

function showNotice(objId)
{
    var obj = document.getElementById(objId);

    if (obj)
    {
        if (obj.style.display != "block")
        {
            obj.style.display = "block";
        }
        else
        {
            obj.style.display = "none";
        }
    }
}

function searchGoods()
{
    var elements  = document.forms['theForm'].elements;
    var filters   = new Object;

    filters.cat_id = elements['cat_id'].value;
    filters.brand_id = elements['brand_id'].value;
    filters.keyword = Utils.trim(elements['keyword'].value);

    sz.loadOptions('get_goods_list', filters);
}
{/literal}

/**
 * 选取上级分类时判断选定的分类是不是底层分类
 */
function catChanged()
{
  var obj = document.forms['theForm'].elements['article_cat'];

  cat_type = obj.options[obj.selectedIndex].getAttribute('cat_type');
  if (cat_type == undefined)
  {
    cat_type = 1;
  }

  if ((obj.selectedIndex > 0) && (cat_type == 2 || cat_type == 4))
  {
    alert(not_allow_add);
    obj.selectedIndex = 0;
    return false;
  }

  return true;
}
</script>
{include file="pagefooter.htm"}

